package ShareLife.gar;


import java.io.IOException;
import java.net.MalformedURLException;

import com.activity.MainActivity;

import tShareLife.facebook.DialogError;
import tShareLife.facebook.Facebook;
import tShareLife.facebook.FacebookError;
import tShareLife.facebook.Facebook.DialogListener;

import android.os.Bundle;
import android.widget.Toast;

public class FbMgr {
	private final class LoginDialogListener implements DialogListener {
		public void onCancel() {
			// TODO future
		}
	
		public void onComplete(Bundle values) {
			mShareLife.fetchWebFacebookInfo();
		}
	
		public void onError(DialogError error) {
			Toast.makeText(mShareLife, "loading facebook authorization page failed, try again later", Toast.LENGTH_LONG).show();
		}
	
		public void onFacebookError(FacebookError error) {
			// TODO future
		}
	} 
	
	public static final String APP_ID = "187466994621698";
	private Facebook mFb;
	MainActivity mShareLife;
	String token;
	String tokenSecret;

	
	public FbMgr(MainActivity mainActivity) {
		mShareLife =  mainActivity;
		mFb = new Facebook(APP_ID);
	}
	
	
	public void authorize() {
		mFb.authorize(mShareLife, new String []{}, new LoginDialogListener());
	}
	
	
	public String request(String reqStr) {
		String result = null;
		try {
			result = mFb.request(reqStr);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
}
